import {
  get,
  post,
  put,
  del
} from "./base_service"


/**
 * 用户信息相关接口
 *
 * allen  2021-08-21
 */

/**
 * 获取用户支付信息
 */
const queryUserPayInfo = () => {
  return new Promise((resolve, reject) => {
    get("/user/pay/info").then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 更新支付信息
 * @param {*} data 
 */
const updatePayInfo = (data) => {
  return new Promise((resolve, reject) => {
    put("/user/update/pay/info", data).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 创建一个商务合作
 * @param {*} data 
 */
const businessCreate = (data) => {
  return new Promise((resolve, reject) => {
    post("/cooperate", data).
      then((data) => {
        if (data.code == 200) {
          resolve(data)
        } else {
          reject(data.msg)
        }
      }).
      catch((e) => {
        reject(e.message)
      })
  })
}

/**
 * 咨询的时候，查询咨询人信息，进行跳转聊天
 */
const queryConsultInfo = (type) => {
  return new Promise((resolve, reject) => {
    get("/cooperate/query?type=" + type).
      then((data) => {
        if (data.code == 200) {
          resolve(data)
        } else {
          reject(data.msg)
        }
      }).
      catch((e) => {
        reject(e.message)
      })
  })
}

/**
 * 绑定挂级关系
 * @param {*} intoType 
 * @param {*} pid 
 */
const bindUserRelation = (intoType, pid, houseNumber = "") => {
  return new Promise((resolve, reject) => {
    get("/user/bindUser?intoType=" + intoType + "&pid=" + pid + "&houseNumber=" + houseNumber).
      then((data) => {
        if (data.code == 200) {
          resolve(data)
        } else {
          reject(data.msg)
        }
      }).
      catch((e) => {
        reject(e.message)
      })
  })
}

/**
 * 更新个人信息
 * @param {*} data 
 */
const updateMyPersonalInfo = (data) => {
  return new Promise((resolve, reject) => {
    put("/user/update/user/base/info", data).
      then((data) => {
        if (data.code == 200) {
          resolve(data)
        } else {
          reject(data.msg)
        }
      }).
      catch((e) => {
        reject(e.message)
      })
  })
}

/**
 * 解绑公司
 */
const cancelBindCompany = () => {
  return new Promise((resolve, reject) => {
    get("/join/employee/unbind/company").
      then((data) => {
        if (data.code == 200) {
          resolve(data)
        } else {
          reject(data.msg)
        }
      }).
      catch((e) => {
        reject(e.message)
      })
  })
}

/**
 * 获取公司报备数量
 */
const getCompanyRecommendNumber = () => {
  return new Promise((resolve, reject) => {
    get("/recommend/personal/company/number").
      then((data) => {
        if (data.code == 200) {
          resolve(data)
        } else {
          reject(data.msg)
        }
      }).
      catch((e) => {
        reject(e.message)
      })
  })
}


/**
 * 根据关键字搜索人员
 * @param {*} words 
 */
const queryAllPersonInfo = (words) => {
  return new Promise((resolve, reject) => {
    get("/user/search?words=" + words).
      then((data) => {
        if (data.code == 200) {
          resolve(data)
        } else {
          reject(data.msg)
        }
      }).
      catch((e) => {
        reject(e.message)
      })
  })
}

/**
 * 提交房源纠错信息
 * @param {*} data 
 */
const submitSuggestReportHouse = (data) => {
  return new Promise((resolve, reject) => {
    post("/suggest/report/house", data).
      then((data) => {
        if (data.code == 200) {
          resolve(data)
        } else {
          reject(data.msg)
        }
      }).
      catch((e) => {
        reject(e.message)
      })
  })
}

/**
 * 房源纠错列表
 * @param {*} page 
 * @param {*} pageSize 
 */
const suggestReportHouseList = (page, pageSize) => {
  return new Promise((resolve, reject) => {
    get("/suggest/manager/report/list?page=" + page + "&pageSize=" + pageSize).
      then((data) => {
        if (data.code == 200) {
          resolve(data)
        } else {
          reject(data.msg)
        }
      }).
      catch((e) => {
        reject(e.message)
      })
  })
}


/**
 * 房源纠错处理
 * @param {*} id 
 */
const suggestReportHouseDeal = (id) => {
  return new Promise((resolve, reject) => {
    get("/suggest/manager/deal?id=" + id).
      then((data) => {
        if (data.code == 200) {
          resolve(data)
        } else {
          reject(data.msg)
        }
      }).
      catch((e) => {
        reject(e.message)
      })
  })
}


/**
 * 创建直播申请提交
 * @param {*} data 
 */
const createLiveApply = (data) => {
  return new Promise((resolve, reject) => {
    post("/live/create", data).
      then((data) => {
        if (data.code == 200) {
          resolve(data)
        } else {
          reject(data.msg)
        }
      }).
      catch((e) => {
        reject(e.message)
      })
  })
}


/**
 * 查询直播列表
 * @param {*} type 
 */
const queryLiveList = (type) => {
  return new Promise((resolve, reject) => {
    get("/live/manager/list?type=" + type).
      then((data) => {
        if (data.code == 200) {
          resolve(data)
        } else {
          reject(data.msg)
        }
      }).
      catch((e) => {
        reject(e.message)
      })
  })
}










module.exports = {
  queryUserPayInfo,
  businessCreate,
  queryConsultInfo,
  updatePayInfo,
  bindUserRelation,
  updateMyPersonalInfo,
  cancelBindCompany,
  getCompanyRecommendNumber,
  queryAllPersonInfo,
  submitSuggestReportHouse,
  suggestReportHouseList,
  suggestReportHouseDeal,
  createLiveApply,
  queryLiveList
}

